package com.lagou.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lagou.common.pojo.Goods;
import com.lagou.common.pojo.Orders;
import com.lagou.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 根据订单id查询订单
     *
     * @param id
     * @return
     */
    @RequestMapping("/query/{id}")
    public Orders queryById(@PathVariable Integer id) {
        return orderService.selectById(id);
    }

    /**
     * 分页查询
     *
     * @param yeshu
     * @return
     */
    @RequestMapping("/page/{yeshu}")
    public Map selectPage(@PathVariable Integer yeshu) {
        Map map = new HashMap<>();
        IPage<Orders> iPage = orderService.selectPage(yeshu);
        List<Orders> goodsList = iPage.getRecords();
        //存储 list:商品集合、total:总条目数
        map.put("list", goodsList);
        map.put("total", iPage.getTotal());
        return map;
    }

    /**
     * 根据订单id查询商品列表
     *
     * @param id
     * @return
     */
    @RequestMapping("/orderGoods/{id}")
    public List<Goods> orderIdGoods(@PathVariable Integer id) {
        List<Goods> goodsList = orderService.selectGoods(id);
        return goodsList;
    }


}
